package Unidad1;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * @author Reynald0
 * @version 2
 */

public class Evento extends JFrame implements ActionListener
{
   private JPanel panel;
   private JButton [] boton;

   public Evento()
   {
      panel = new JPanel(new GridLayout(3,1));
      add(panel);
      
      agregarBotones(3);
      setSize(300,400);
      setVisible(true);
      
      setDefaultCloseOperation(EXIT_ON_CLOSE); 
   }
   
   public void agregarBotones(int pCantidad)
   {
      boton = new JButton [pCantidad];
      
      for(int i= 0; i < boton.length; i++)
      {
         boton[i] = new JButton("AAA" + i);
         boton[i].addActionListener(this);
         panel.add(boton[i]);
      }
   }
   
   
   public void actionPerformed(ActionEvent pE)
   {
      if (pE.getSource().equals(boton[0]))
         System.out.println("0");
      else if (pE.getSource().equals(boton[1]))
         System.out.println("1");
      if (pE.getSource().equals(boton[2]))
         System.out.println("2");
   }
   
   
   public static void main(String[] args)
   {
      new Evento();
   }
}
